//
//  CABasicAnimation_cornerRadius.swift
//  APSwift
//
//  Created by jianbo.pei on 2022/8/17.
//

import UIKit

class CABasicAnimation_cornerRadius: UIViewController {

    private var redView: UIView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        redView = UIView(frame: CGRect(x: 50, y: 150, width: 200, height: 200))
        view.addSubview(redView)
        redView.backgroundColor = .red
        
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        let basicAnimation = CABasicAnimation(keyPath: CALayer.KeyPath.cornerRadius)
        basicAnimation.fromValue = 0
        basicAnimation.toValue = 50
        basicAnimation.duration = 2
        /// 是否按照原来的路径返回
        basicAnimation.autoreverses = false
        /// 设置重复的次数
//        basicAnimation.repeatCount = HUGE
        basicAnimation.isRemovedOnCompletion = false
        basicAnimation.fillMode = .forwards
        redView.layer.add(basicAnimation, forKey: nil)
    }

}
